<template>
  <div class="myApplications">
    <myApplicationsHead />
    <div class="list-view">
      <div class="session-view" v-for="session of listData" :key="session.sessionTitle">
        <div class="session-title">
          <text>{{ session.sessionTitle }}</text>
        </div>
        <div
          v-for="(item, index) of session.items"
          :key="index"
          @click="onSelectItem(item)"
        >
          <myApplicationCell :item="item" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, computed } from "vue";
import { getToken } from "@/utils/auth";
import myApplicationsHead from "./myApplicationHead.vue";
import myApplicationCell from "./myApplicationCell.vue";
import { useCommonStore, FuncStatusEnum } from "@/store";
import { getUserInfo } from "@/utils/auth";

const commonStore = useCommonStore();

const itemType = {
  // 产品价值导航家
  priceNav: 1,
  // 软件报价小助理
  quotationAssistant: 2,
  // 定制业务咨询师
  businessConsulting: 3,
  // 企业客户侦查机
  customer: 4,
  // 客户案例全景库
  customerCases: 5,
  // 沉默唤醒器
  wakeup: 6,
  // 财务问答专家
  financialAssistant: 7,
  // 法务助手
  legalAffairsAssistant: 8,
  // 定制包生成助手
  packageAssistant: 9,
};

onMounted(() => {
  initData();
});

const listData = ref([]);

async function initData()  {
  const meetBaseUrl = import.meta.env.VITE_BASE_API;
  const xmateBaseUrl = import.meta.env.VITE_XMATE_BASE_URL;
  let userInfo = getUserInfo();
  let token = getToken()
//销售赋能大单滚滚
  addSession("");

  await commonStore.getFuncpPointsAction()

  if (commonStore.salesCompanyInApp) {
    addItem({
      title: "企业信息侦察机",
      type: itemType.customer,
      des: "获取客户信息，轻松不止一点点",
      icon:
        "https://meetcdn.yxt.com/test-flutter-web/img/xmate-application/companyInfo.png",
      url: `${xmateBaseUrl}/postmeet-xmate-h5/#/customer?token=${token}&hiddenNav=true`,
    });
  }

  if (commonStore.salesProductInApp) {
    addItem({
      title: "智能商品推荐师",
      type: itemType.wakeup,
      des: "根据客户需求，个性化推荐最佳商品",
      icon: "https://meetcdn.yxt.com/test-flutter-web/img/xmate-application/goods.png",
      url: `${meetBaseUrl}/xmate-h5/#/productAssistant?userid=${userInfo.id}&xm=true&token=${token}`,
    });
  }
}

function addItem(item) {
  if (!listData.value || listData.value.length === 0) {
    return;
  }
  const lastSession = listData.value[listData.value.length - 1];
  lastSession.items.push(item);
}

function addSession(title) {
  listData.value.push({
    sessionTitle: title,
    items: [],
  });
}

function onSelectItem(item) {
  window.open(item.url, "_blank");
}

function makeAIBootURL() {}
</script>

<style lang="less" scoped>
.myApplications {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(180deg, #e9f1ff 0%, #f5f9ff 100%);
  display: flex;
  flex-direction: column;

  .head-view {
    position: relative;
    width: 100%;
    height: 233px;
    background: #edf3ff;

    .background-img {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
    }
  }

  .list-view {
    position: relative;
    // top: -10px;
    overflow-y: auto;
    flex: 1;
  }

  .session-view {
    margin-bottom: 24px;
  }

  .session-title {
    font-size: 16px;
    font-weight: 500;
    color: #262626;
    line-height: 24px;
    margin-bottom: 12px;
  }

  .list-view {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
